﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using KinectDwa;

namespace Kinect.Tests
{
    public class KinectButtonBase : Button
    {
        public ButtonMode ButtonMode = ButtonMode.Normal;
     
        public Visibility LargeText
        {
            get { return (Visibility)GetValue(LargeTextProperty); }
            set { SetValue(LargeTextProperty, value); }
        }

        public Visibility SmallText
        {
            get 
            {
                return (Visibility)GetValue(LargeTextProperty) == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            }

        }

        // Using a DependencyProperty as the backing store for LargeText.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty LargeTextProperty =
            DependencyProperty.Register("LargeText", typeof(Visibility), typeof(KinectButtonBase), new UIPropertyMetadata(Visibility.Visible));



        public KinectButtonBase()
        {
            Style = (Style)App.Current.Resources["KinectButtonStyle"];

            DataContext = this;

            ClickMode = System.Windows.Controls.ClickMode.Press;

            Click += new RoutedEventHandler(KinectButtonBase_Click);
        }

        void KinectButtonBase_Click(object sender, RoutedEventArgs e)
        {
            StaticTestEngine.ClickSound.Play();

            StaticTestEngine.AddClickMarker(System.Windows.Forms.Cursor.Position, true, Tag.ToString());
        }

        public void Rectangle_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            VisualStateManager.GoToState(this, "Hover", false);
        }

        public void Background_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(ClickEvent));

            VisualStateManager.GoToState(this, "Normal", false);
        }

        public void Button_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (ButtonMode == KinectDwa.ButtonMode.Sticky)
            {
                StickyButtonHandler.Focus(this);
            }
            else
            {
                StickyButtonHandler.Focus(null);
            }

            this.Focus();
        }

        public void DoubleAnimationUsingKeyFrames_Completed(object sender, System.EventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(ClickEvent));

            VisualStateManager.GoToState(this, "Normal", false);
        }

    }
}
